/**
 * @Title:  AttentionDynamicsActivity.java
 * @Copyright:  XXX Co., Ltd. Copyright YYYY-YYYY,  All rights reserved 
 * @Description:  TODO<请描述此文件是做什么的> 
 * @author:  MeiYi
 * @data:  2015-12-7 上午10:20:14 
 * @version:  V1.0
 */

package artid.com.arttogo.fragment;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;

import com.android.volley.RequestQueue;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.ImageLoader;
import com.android.volley.toolbox.Volley;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.animation.GlideAnimation;
import com.bumptech.glide.request.target.SimpleTarget;

import java.util.ArrayList;
import java.util.List;

import artid.com.arttogo.R;
import artid.com.arttogo.activity.AucOrgDetActivity;
import artid.com.arttogo.activity.AuctionOrganizationActivity;
import artid.com.arttogo.activity.CollecterActivity;
import artid.com.arttogo.activity.CollectionDetailPagerActivity;
import artid.com.arttogo.activity.DotPraiseUser_Activity;
import artid.com.arttogo.activity.OrganizationActivity;
import artid.com.arttogo.activity.PhotoActivity;
import artid.com.arttogo.activity.ReportActivity;
import artid.com.arttogo.adapter.ArtListDetailAdapter;
import artid.com.arttogo.bean.ArtComment;
import artid.com.arttogo.bean.ArtFavorite;
import artid.com.arttogo.bean.ArtShownum;
import artid.com.arttogo.bean.ArtistFollow;
import artid.com.arttogo.bean.NewartDetails;
import artid.com.arttogo.bean.OneStateIntParser;
import artid.com.arttogo.bean.RqCode;
import artid.com.arttogo.bean.ShareItem;
import artid.com.arttogo.bean.ShowPhoto;
import artid.com.arttogo.db.Cache;
import artid.com.arttogo.network.AppUtil;
import artid.com.arttogo.network.BitmapCache;
import artid.com.arttogo.network.VolleyBasic;
import artid.com.arttogo.network.VolleyCallback;
import artid.com.arttogo.network.VolleyData;
import artid.com.arttogo.network.VolleyMap;
import artid.com.arttogo.utils.Config;
import artid.com.arttogo.utils.MyBitmapImageViewTarget;
import artid.com.arttogo.utils.VeDate;
import artid.com.arttogo.view.CircleImageView;
import artid.com.arttogo.view.MyAdGallery;
import artid.com.arttogo.view.MyEditText;
import artid.com.arttogo.view.MyListView;
import artid.com.arttogo.view.ZoomScollView;
import artid.com.arttogo.view.pulllist.PullToRefreshLayout;

import static artid.com.arttogo.R.id.clt_det_icon_num;


/**
 * 艺术品详情
 *
 * @author 熊彬
 * @data: 2015-12-7 上午10:20:14
 * @version: V1.0
 */
@SuppressLint("ValidFragment")
public class CollectDetailFragment extends BaseFragment implements
		OnClickListener {
	private Context mContext;
	//					主图     点赞      取消点赞    收藏      取消收藏
	private ImageView cImage,  imgLike, imgUnlike, imgColl, imgUncoll;
	View viewlike, viewCollect, viewComment;
	private TextView config, proDnum, textlike, textpl, textsc, textjzjg;
	private ImageLoader mImageLoader;
	ImageView imageAuth;
	MyListView mlist;
	String id = "";
	MyEditText editComment;
	RqCode codeItem = null;
	// ImageView mImgShare;w
	PullToRefreshLayout mPullLayout;
	int pageIndex = 1, pagesize = 10;
	ZoomScollView mscroll;
	View hideView;
	View slideMain, viewPic;
	ShareItem shareItem = null;
	String srcImg = "";
	String uid = "";
	ArtListDetailAdapter adapter;
	//判断是否是机构
	Boolean isOrg = false;
	Boolean isReplyPerson = false;
	String commentId = "";
	private int width, height;
	View v;
	String oldid;
	View blankView;
	//包含机构的view
	View organ, organCode;
	ArrayList<String> imgurls = new ArrayList<String>(),
			strtitles = new ArrayList<String>();// 用于展示大图
	ShowPhoto photoItem = new ShowPhoto();
	Boolean isAdded = false;
	View mViewMore;
	NewartDetails MainData;
	LinearLayout mLineIcon;
	TextView mTextArtName;
	TextView mTextRecState;// 备案状态
	TextView mTextReadNum;// 阅读量
	TextView mTextAuther;
	TextView mTextTime;
	TextView mTextInfo;
	Button mBtnChat;//聊天
	ImageView mImgHead;
	TextView mTextArtistName;
	TextView mTextArtisNum;
	View mViewFollow, mViewFollowed;
	TextView mTextReplyNum;
	int gznum = 0;
	TextView mTextIconNum;
	View mViewIcon;
	View mViewBack;
	View mViewReplyIcon;//回复
	TextView mTextFollowNum;
	ImageView mImgLike;
	Boolean islike = false;
	RelativeLayout artistInfoRL;
	String artistID;// 艺术家ID
	private String titileName;

	// ImageView headIconForLike;
	@Override
	public void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		mContext = getActivity();
		Bundle args = getArguments();
		id = args.getString("id");
		Boolean org = args.getBoolean("isOrg");
		if (org != null) {
			isOrg = org;
		}
		RequestQueue mQueue = Volley.newRequestQueue(mContext);
		mImageLoader = new ImageLoader(mQueue, new BitmapCache());
	}

	public CollectDetailFragment(String titileName) {
		super();
		this.titileName = titileName;
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
							 Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		v = inflater.inflate(R.layout.activity_collection_details_pager, null);
		mBack = (ImageView) v.findViewById(R.id.back_btn);
		mBack.setVisibility(View.VISIBLE);
		mBack.setOnClickListener(this);
		mTittle = (TextView) v.findViewById(R.id.tittle_text);
		// mTittle.setText(titileName);
		mViewReplyIcon = (View) v.findViewById(R.id.clt_det_pl);
		mViewReplyIcon.setOnClickListener(this);
		mLineIcon = (LinearLayout) v.findViewById(R.id.clt_det_layout_icon);
		mTextArtName = (TextView) v.findViewById(R.id.clt_det_name);
		mTextRecState = (TextView) v.findViewById(R.id.clt_det_isrecord);
		mTextReadNum = (TextView) v.findViewById(R.id.clt_det_read_num);
		mTextAuther = (TextView) v.findViewById(R.id.clt_det_artist);
		mTextTime = (TextView) v.findViewById(R.id.clt_det_time);
		mTextInfo = (TextView) v.findViewById(R.id.clt_det_type_size_time);
		mBtnChat = (Button) v.findViewById(R.id.clt_det_chat);
		mBtnChat.setOnClickListener(this);
		mImgHead = (ImageView) v.findViewById(R.id.clt_det_headimg);
		mTextArtistName = (TextView) v.findViewById(R.id.clt_det_artist_name);
		mTextArtisNum = (TextView) v.findViewById(R.id.clt_det_artist_num);
		mViewFollow = (View) v.findViewById(R.id.clt_det_follow);
		mViewFollowed = (View) v.findViewById(R.id.clt_det_follow_ed);
		mTextReplyNum = (TextView) v.findViewById(R.id.clt_det_reply_num);
		mTextIconNum = (TextView) v.findViewById(clt_det_icon_num);
		mViewIcon = (View) v.findViewById(R.id.clt_det_icon_view);
		mViewIcon.setOnClickListener(this);
		mViewBack = (View) v.findViewById(R.id.clt_det_back);
		mViewBack.setOnClickListener(this);
		mTextFollowNum = (TextView) v.findViewById(R.id.clt_det_artist_follow);
		mImgLike = (ImageView) v.findViewById(R.id.clt_det_like);
		mImgLike.setOnClickListener(this);
		artistInfoRL = (RelativeLayout) v
				.findViewById(R.id.clt_det_artistInfoRL);
		artistInfoRL.setOnClickListener(this);
		mViewMore = (View) v.findViewById(R.id.clt_det_more);
		mViewMore.setOnClickListener(this);
		organ = (View) v.findViewById(R.id.coldet_org);
		organCode = (View) v.findViewById(R.id.coldet_org_code);
		blankView = (View) v.findViewById(R.id.det_hide);
		hideView = (View) v.findViewById(R.id.collection_det_hideview);
		imageAuth = (ImageView) v.findViewById(R.id.image_is_auth);
		cImage = (ImageView) v.findViewById(R.id.iv_coll_img);
		cImage.setOnClickListener(this);
		mscroll = (ZoomScollView) v.findViewById(R.id.collection_detail_scroll);
		mscroll.setIsDrop(false);
		imgLike = (ImageView) v.findViewById(R.id.img_artwork_det_like);
		viewComment = (View) v.findViewById(R.id.artdet_comment_show);
		viewComment.setOnClickListener(this);
		viewlike = (View) v.findViewById(R.id.view_like);
		viewlike.setOnClickListener(this);
		imgUnlike = (ImageView) v.findViewById(R.id.img_artwork_det_unlike);
		imgColl = (ImageView) v.findViewById(R.id.icon_collect_sel);
		viewCollect = (View) v.findViewById(R.id.view_collect);
		viewCollect.setOnClickListener(this);
		imgUncoll = (ImageView) v.findViewById(R.id.icon_collect_unsel);
		config = (TextView) v.findViewById(R.id.tv_coll_config);
		proDnum = (TextView) v.findViewById(R.id.tv_coll_product);
		textlike = (TextView) v.findViewById(R.id.artdetal_z);
		textpl = (TextView) v.findViewById(R.id.artdetal_pl);
		textsc = (TextView) v.findViewById(R.id.artdetal_sc);
		textjzjg = (TextView) v.findViewById(R.id.artdetal_jzjg);
		editComment = (MyEditText) v.findViewById(R.id.artdet_comment_edit);
		editComment.setOnClickListener(this);
		editComment
				.setOnEditorActionListener(new TextView.OnEditorActionListener() {
					public boolean onEditorAction(TextView v, int actionId,
												  KeyEvent event) {
						if (actionId == EditorInfo.IME_ACTION_DONE
								|| actionId == EditorInfo.IME_ACTION_SEARCH
								|| (event != null && event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) {
							if (TextUtils.isEmpty(editComment.getText()
									.toString())) {
								Config.showTip(getActivity(), "评论不能为空");
								return false;
							}
							if (TextUtils.isEmpty(editComment.getHint()
									.toString())) {
								isReplyPerson = false;
							}
							if (isReplyPerson) {
								Replycomment(commentId);
							} else {
								reqArtReplycomment();
							}

							return false;
						}
						return false;
					}
				});

		mlist = (MyListView) v.findViewById(R.id.list_artdetal);

		mPullLayout = (PullToRefreshLayout) v.findViewById(R.id.refresh_view);

		mPullLayout.setOnRefreshListener(new PullToRefreshLayout.OnRefreshListener() {

			@Override
			public void onRefresh(PullToRefreshLayout pullToRefreshLayout) {
				// TODO Auto-generated method stub
				pageIndex = 1;
				if (isOrg) {
					id = oldid;
				}
				reqData();
				reqCommentData();
				reqisLike(id);
			}

			@Override
			public void onLoadMore(PullToRefreshLayout pullToRefreshLayout) {
				// TODO Auto-generated method stub
				// pullToRefreshLayout.setBottomDismiss();
				pageIndex++;
				reqCommentData();
			}
		});
		adapter = new ArtListDetailAdapter(mContext);
		DisplayMetrics dm = new DisplayMetrics();
		getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);
		width = dm.widthPixels;
		height = dm.heightPixels;
		ViewGroup.LayoutParams lp = cImage.getLayoutParams();
		lp.width = width;
		lp.height = width * 3;
		cImage.setLayoutParams(lp);
		isViewSetup = true;
		isAdded = false;
		return v;
	}

	/**
	 * 请求主数据
	 */
	void reqData() {
		String url = "";
		if (isOrg) {
			// reqcode(id);
			url = Cache.institutionartInfo;
			// return;
		} else {
			url = Cache.Newart_artDetails;
		}
		VolleyBasic.getInstance(getActivity()).post(url,
				VolleyMap.getInstance().Newart_artDetails(id, "500", ""),
				NewartDetails.class, new VolleyCallback() {
					@Override
					public void onSuccess(VolleyData vd) {
						// TODO Auto-generated method stub
						final NewartDetails item = (NewartDetails) vd.getData();
						MainData = item;
						if (!item.getIs_support().equals("1")) {
							islike = false;
							mImgLike.setImageResource(R.drawable.like_orange);
						} else {
							mImgLike.setImageResource(R.drawable.icon_like_sel);
							islike = true;
						}
						mTextArtName.setText(item.getTitle());
						if (item.getStatus().equals("-1")) {
							mTextRecState.setText("未通过审核");
						} else if (item.getStatus().equals("1")) {
							mTextRecState.setText("备案中");
						} else if (item.getStatus().equals("2")) {
							mTextRecState.setText("已备案");
						}
						mTittle.setText(item.getTitle());
						mTextReadNum.setText(item.getScanNum());
						mTextAuther.setText(item.getAuthor());
						mTextTime.setText(item.getCreate_time());
						String cate = "", size = "", year = "";
						if (!item.getCat_id().isEmpty()) {
							cate = item.getCat_id() + "/";
						}
						if (!item.getSize().isEmpty()) {
							size = item.getSize() + "/";
						}
						mTextInfo.setText(cate + size + item.getArtyear());

						if (!TextUtils.isEmpty(item.getCode())) {
							proDnum.setText(item.getCode());
						} else {
							organCode.setVisibility(View.GONE);

						}
						if (!TextUtils.isEmpty(item.getOrganizer())) {
							textjzjg.setText(item.getOrganizer());
						} else {
							organ.setVisibility(View.GONE);
						}
						if (TextUtils.isEmpty(item.getOrganizer())
								&& TextUtils.isEmpty(item.getCode())) {
							// v.findViewById(R.id.view_coldet_certif).setVisibility(View.GONE);
						}
						config.setText(item.getDetail());
						if (item.getIs_favorite().equals("1")) {
							AppUtil.isCollect = true;
						} else {
							AppUtil.isCollect = false;
						}
						artistID = item.getArtist_id();
						Glide.with(mContext)
								.load(item.getHeadurl() + "_" + "100"
										+ "x10.png").asBitmap().centerCrop()
								.placeholder(R.drawable.ic_menu_rotate)
								.error(R.drawable.ic_menu_rotate)
								.into(new MyBitmapImageViewTarget(mImgHead));
						Glide.with(getActivity())
								.load(item.getHeadurl() + "_" + "100"
										+ "x10.png")
								// .load("/storage/emulated/0/Tencent/QQfile_recv/55mb.jpg")
								.asBitmap().centerCrop()
								.into(new SimpleTarget<Bitmap>() {
									@Override
									public void onResourceReady(
											Bitmap resource,
											GlideAnimation<? super Bitmap> glideAnimation) {
										mImgHead.setImageBitmap(resource);
										// headIconForLike.setImageBitmap(resource);

									}
								});
						mImgHead.setDrawingCacheEnabled(true);
						mTextArtistName.setText(item.getRealname());
						mTextArtisNum.setText(item.getArtnum() + "件作品   ");
						mTextFollowNum.setText(item.getFollow_num() + "人关注");
						gznum = Integer.valueOf(item.getFollow_num());

						mViewFollow.setOnClickListener(listenerGz(
								item.getArtist_id(), true));
						mViewFollowed.setOnClickListener(listenerGz(
								item.getArtist_id(), false));
						if (item.getIs_follow().equals("1")) {
							mViewFollowed.setVisibility(View.VISIBLE);
							mViewFollow.setVisibility(View.GONE);
						} else {
							mViewFollowed.setVisibility(View.GONE);
							mViewFollow.setVisibility(View.VISIBLE);
						}
						mTextReplyNum.setText(item.getComment_num());
						mTextIconNum.setText(item.getFav_num());
						listIcon = item.getUserimg();
						setHeadIcon(item.getUserimg());

						Glide.with(getActivity())
								.load(item.getPic_url() + AppUtil.picWidthUrl)
								.asBitmap().into(new SimpleTarget<Bitmap>() {
							@Override
							public void onResourceReady(
									Bitmap resource,
									GlideAnimation<? super Bitmap> glideAnimation) {
								ViewGroup.LayoutParams lp = cImage
										.getLayoutParams();
								int w = resource.getWidth();
								int h = resource.getHeight();

								lp.width = width;
								lp.height = h * width / w;

								cImage.setLayoutParams(lp);
								cImage.setMaxWidth(width);
								cImage.setMaxHeight((int) (width * 5));
								cImage.setImageBitmap(resource);
								mscroll.setZoomView(cImage, true);
								try {
									Animation animation2 = AnimationUtils
											.loadAnimation(mContext,
													R.anim.fade_out);
									animation2
											.setAnimationListener(new AnimationListener() {

												@Override
												public void onAnimationStart(
														Animation arg0) {
													// TODO
													// Auto-generated
													// method stub

												}

												@Override
												public void onAnimationRepeat(
														Animation arg0) {
													// TODO
													// Auto-generated
													// method stub

												}

												@Override
												public void onAnimationEnd(
														Animation arg0) {
													// TODO
													// Auto-generated
													// method stub

													blankView
															.setVisibility(View.GONE);
												}
											});
									blankView
											.startAnimation(animation2);
								} catch (Exception e) {
									// TODO: handle exception
								}

							}
						});

						photoItem.setInfo(item.getDetail());
						photoItem.setName(item.getTitle());
						photoItem.setUrl(item.getPic_url());
						srcImg = item.getPic_url();

						textlike.setText("点赞  (" + item.getCommend_num() + ")");
						textpl.setText("评论  (" + item.getComment_num() + ")");
						textsc.setText("收藏  (" + item.getFav_num() + ")");
						//设置分享
						shareItem = new ShareItem();
						shareItem.setContent(item.getDetail());
						shareItem.setImageUrl(item.getPic_url());
						shareItem.setTitle(item.getTitle());
						shareItem.setUrl(item.getSharelink());
						shareItem.setUid(item.getUid());
						shareItem.setHeadUrl(item.getHeadurl());
						shareItem.setAname(item.getRealname());
						// CollectionDetailPagerActivity.listshare.set(
						// CollectionDetailPagerActivity.index, shareItem);
						if (item.getStatus().equals("2")) {
							imageAuth.setVisibility(View.VISIBLE);
						}
						// CollectionDetailPagerActivity.mTittle.setText(item
						// .getTitle());
						if (item.getIs_artist().equals("2")) {
							mViewFollow.setVisibility(View.GONE);
							mBtnChat.setVisibility(View.GONE);
							mTextArtisNum.setVisibility(View.GONE);
							mTextFollowNum.setVisibility(View.GONE);
							;
						}

					}

					@Override
					public void onError(VolleyError volleyError) {
						// TODO Auto-generated method stub

					}
				});
		reqCommentData();
		reqisLike(id);
	}

	ArrayList<String> listIcon;

	//设置点赞的头像小图列表
	void setHeadIcon(ArrayList<String> list) {
		mTextIconNum.setText(list.size()+"");
		mLineIcon.removeAllViews();
		for (int i = 0; i < list.size(); i++) {
			String headuri = list.get(i);
			final CircleImageView img = new CircleImageView(mContext);
			img.setImageResource(R.drawable.head_sq);
			android.widget.LinearLayout.LayoutParams params = new android.widget.LinearLayout.LayoutParams(
					VeDate.dip2px(mContext, 30), VeDate.dip2px(mContext, 30));
			params.setMargins(VeDate.dip2px(mContext, 10), 0, VeDate.dip2px(mContext, 10), 0);
			img.setLayoutParams(params);
			mLineIcon.addView(img);
			Glide.with(getActivity()).load(headuri + AppUtil.picWidthUrl)
					// .load("/storage/emulated/0/Tencent/QQfile_recv/55mb.jpg")
					.asBitmap().into(new SimpleTarget<Bitmap>() {
				@Override
				public void onResourceReady(Bitmap resource,
											GlideAnimation<? super Bitmap> glideAnimation) {
					/*CircleImageView img = new CircleImageView(mContext);
					img.setImageBitmap(resource);
					android.widget.LinearLayout.LayoutParams params = new android.widget.LinearLayout.LayoutParams(
							VeDate.dip2px(mContext, 30), VeDate.dip2px(mContext, 30));
					params.setMargins(VeDate.dip2px(mContext, 10), 0, VeDate.dip2px(mContext, 10), 0);
					img.setLayoutParams(params);
					mLineIcon.addView(img);*/
					img.setImageBitmap(resource);
				}
			});
		}
	}

	View.OnClickListener listenerGz(final String id, final Boolean setFollow) {
		return new View.OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				if (!AppUtil.LoginVer(getActivity())) {
					reqFollowArtist(id, setFollow);
				}
			}
		};
	}

	void reqFollowArtist(String id, final Boolean setFollow) {
		String state = "";
		if (setFollow) {
			state = "1";
		} else {
			state = "2";
		}
		VolleyBasic.getInstance(getActivity()).post(
				Cache.artistFollow,
				VolleyMap.getInstance().artistFollow(
						AppUtil.getUser().getToken(), id, state),
				ArtistFollow.class, new VolleyCallback() {

					@Override
					public void onSuccess(VolleyData vd) {
						// TODO Auto-generated method stub
						ArtistFollow itemArtistFollow = (ArtistFollow) vd
								.getData();

						if (itemArtistFollow.getState().equals("1")) {
							if (setFollow) {
								gznum++;
								mViewFollow.setVisibility(View.GONE);
								mViewFollowed.setVisibility(View.VISIBLE);

							} else {
								gznum--;
								mViewFollow.setVisibility(View.VISIBLE);
								mViewFollowed.setVisibility(View.GONE);
							}
							mTextFollowNum.setText(String.valueOf(gznum)
									+ "人关注");
						}
					}

					@Override
					public void onError(VolleyError volleyError) {
						// TODO Auto-generated method stub

					}
				});
	}

	Boolean isViewSetup = false;

	// 让缓存的页面不加载

	@Override
	public void setUserVisibleHint(boolean isVisibleToUser) {
		super.setUserVisibleHint(isVisibleToUser);
		if (isVisibleToUser) {
			// 相当于Fragment的onResume
			if (isViewSetup && isAdded == false) {
				reqData();
				mscroll.fullScroll(ScrollView.FOCUS_UP);
				disableAutoScrollToBottom();
			}
		} else {
			isAdded = true;
			id = oldid;

		}
	}

	/**
	 * 处理侧滑自动滚到底部
	 */
	private void disableAutoScrollToBottom() {
		mscroll.setDescendantFocusability(ViewGroup.FOCUS_BEFORE_DESCENDANTS);
		mscroll.setFocusable(true);
		mscroll.setFocusableInTouchMode(true);
		mscroll.setOnTouchListener(new OnTouchListener() {

			@Override
			public boolean onTouch(View arg0, MotionEvent arg1) {
				// TODO Auto-generated method stub
				arg0.requestFocusFromTouch();
				return false;
			}
		});
	}

	MyAdGallery gallery;

	//初始化轮播图
	void initSlide() {
		slideMain = (View) v.findViewById(R.id.slideView);

		LinearLayout dotLayout = (LinearLayout) v.findViewById(R.id.dotLayout);
		ArrayList<ImageView> dotViewList = new ArrayList<ImageView>();
		ImageView iv1 = (ImageView) v.findViewById(R.id.iv_carousel1);
		dotViewList.add(iv1);
		dotViewList.add(iv1);
		dotViewList.add(iv1);
		// ImageView iv1 = (ImageView) findViewById(R.id.iv_carousel1);
		// imgFocusList = new ArrayList<String>();
		// urlFocusList = new ArrayList<String>();

		slideMain.setVisibility(View.VISIBLE);
		gallery = (MyAdGallery) v.findViewById(R.id.myviewPager);
		gallery.setmPager(CollectionDetailPagerActivity.mViewPager);
		String imgarrstr = "";
		// for (RqCode.PointImg index : codeItem.getList()) {
		// String imgString = index.getImgurl();
		// imgFocusList.add(imgString);
		// urlFocusList.add(imgString);
		// imgarrstr += (index.getImgurl() + ",");
		// // dotLayout.addView(iv1);
		// dotViewList.add(iv1);
		// }
		String[] arrImg = {
				"http://172.16.0.3:80/upload/artVerification/art/2016033014383222756.png",
				"http://172.16.0.3:80/upload/artVerification/art/2016033014383222756.png",
				"http://172.16.0.3:80/upload/artVerification/art/2016033014383222756.png" };
		gallery.start(getActivity(), arrImg, null, 3000, dotViewList,
				R.drawable.point_pressed, R.drawable.point_unpressed);
	}

	/**
	 * 从机构、搜索进入，请求之后替换id
	 *
	 * @param id
	 */
	void reqcode(String id) {
		oldid = id;
		VolleyBasic.getInstanceNoDialog(getActivity()).post(Cache.rqCode,
				VolleyMap.getInstance().rqCode(id, "1"), RqCode.class,
				new VolleyCallback() {

					@Override
					public void onSuccess(VolleyData vd) {
						// TODO Auto-generated method stub
						RqCode item = (RqCode) vd.getData();
						Glide.with(getActivity())
								.load(item.getPic_url() + AppUtil.picWidthUrl)
								// .load("/storage/emulated/0/Tencent/QQfile_recv/55mb.jpg")
								.asBitmap().into(new SimpleTarget<Bitmap>() {
							@Override
							public void onResourceReady(
									Bitmap resource,
									GlideAnimation<? super Bitmap> glideAnimation) {
								ViewGroup.LayoutParams lp = cImage
										.getLayoutParams();
								int w = resource.getWidth();
								int h = resource.getHeight();

								lp.width = width;
								lp.height = h * width / w;

								cImage.setLayoutParams(lp);

								cImage.setMaxWidth(width);
								cImage.setMaxHeight((int) (width * 5));
								cImage.setImageBitmap(resource);
								// System.out.println("bitmap="+bitmap.getWidth()+"="+bitmap.getHeight());
								Animation animation2 = AnimationUtils
										.loadAnimation(mContext,
												R.anim.fade_out);
								animation2
										.setAnimationListener(new AnimationListener() {

											@Override
											public void onAnimationStart(
													Animation arg0) {
												// TODO Auto-generated
												// method stub

											}

											@Override
											public void onAnimationRepeat(
													Animation arg0) {
												// TODO Auto-generated
												// method stub

											}

											@Override
											public void onAnimationEnd(
													Animation arg0) {
												// TODO Auto-generated
												// method stub

												blankView
														.setVisibility(View.GONE);
											}
										});
								blankView.startAnimation(animation2);
							}
						});

						for (int i = 0; i < item.getList().size(); i++) {
							imgurls.add(item.getList().get(i).getImgurl());
							strtitles.add(item.getList().get(i).getText());
						}
						// title.setText(item.getTitle());
						mTittle.setText(item.getTitle());
						config.setText(item.getDetail());
						textlike.setText("点赞  (" + item.getCommend_num() + ")");
						textpl.setText("评论  (" + item.getComment_num() + ")");
						textsc.setText("收藏  (" + item.getFav_num() + ")");
						if (!TextUtils.isEmpty(item.getCode())) {
							proDnum.setText(item.getCode());
						} else {
							organCode.setVisibility(View.GONE);

						}
						if (!TextUtils.isEmpty(item.getOrganizer())) {
							textjzjg.setText(item.getOrganizer());
						} else {
							organ.setVisibility(View.GONE);
						}
						if (TextUtils.isEmpty(item.getOrganizer())
								&& TextUtils.isEmpty(item.getCode())) {
//					v.findViewById(R.id.view_coldet_certif)
//					.setVisibility(View.GONE);
						}
						CollectDetailFragment.this.id = item.getArt_id();
						shareItem = new ShareItem();
						shareItem.setTitle(item.getTitle());
						shareItem.setContent(item.getDetail());
						shareItem.setUrl(item.getShareurl());
						shareItem.setImageUrl(item.getPic_url());
						shareItem.setAname(item.getRealname());
						if (item.getStatus().equals("2")) {
							imageAuth.setVisibility(View.VISIBLE);
						}
						// if
						// (CollectionDetailPagerActivity.mViewPager.getCurrentItem()-CollectionDetailPagerActivity.listshare.size()>-1)
						// {
						// CollectionDetailPagerActivity.listshare.set(
						// CollectionDetailPagerActivity.index, shareItem);
						// }
						photoItem.setInfo(item.getDetail());
						photoItem.setName(item.getTitle());
						photoItem.setUrl(item.getPic_url());
						CollectionDetailPagerActivity.mTittle.setText(item
								.getTitle());
						reqCommentData();
						reqisLike(CollectDetailFragment.this.id);
					}

					@Override
					public void onError(VolleyError volleyError) {
						// TODO Auto-generated method stub

					}
				});
	}

	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onActivityCreated(savedInstanceState);
		if (CollectionDetailPagerActivity.isCreat) {
			reqData();
			mscroll.fullScroll(ScrollView.FOCUS_UP);
			disableAutoScrollToBottom();
			CollectionDetailPagerActivity.isCreat = false;
		}

	}

	PopupWindow mPw;
	TextView report, reply, cancel;

	void reqCommentData() {
		VolleyBasic.getInstanceNoDialog(getActivity()).post(
				Cache.artComment,
				VolleyMap.getInstance().artComment(id,
						String.valueOf(pageIndex), String.valueOf(pagesize)),
				ArtComment.class, new VolleyCallback() {

					@Override
					public void onSuccess(VolleyData vd) {
						// TODO Auto-generated method stub
						mPullLayout.loadmoreFinish(mPullLayout.SUCCEED);
						final List<ArtComment> list = (List<ArtComment>) vd
								.getList();
						if (list.isEmpty()) {
							// Config.showTip(CollectionDetailsActivity.this,
							// "无数据");
							return;
						}
						if (pageIndex != 1) {
							adapter.addList(list);
							mlist.setOnItemClickListener(new OnItemClickListener() {

								@Override
								public void onItemClick(AdapterView<?> arg0,
														View arg1, int arg2, long arg3) {
									// TODO Auto-generated method stub
									String replyPreFix = "";
									replyPreFix = "回复"
											+ adapter.listdata.get(arg2)
											.getRealname() + ":";
									commentId = adapter.listdata.get(arg2)
											.getMessid();
									isReplyPerson = true;
									startComment(replyPreFix);
								}
							});

							return;
						}
						mlist.setAdapter(adapter);
						adapter.setdata(list);
						LayoutInflater layoutInflater = (LayoutInflater) mContext
								.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
						View prView = layoutInflater.inflate(
								R.layout.pop_comment, null);// 自定义的布局文件
						report = (TextView) prView
								.findViewById(R.id.cmt_report);
						reply = (TextView) prView.findViewById(R.id.cmt_reply);
						cancel = (TextView) prView
								.findViewById(R.id.cmt_cancel);
						mPw = new PopupWindow(prView,
								LayoutParams.WRAP_CONTENT,
								LayoutParams.WRAP_CONTENT);
						mPw.setBackgroundDrawable(new BitmapDrawable());
						mPw.setOutsideTouchable(true);
						mlist.setOnItemClickListener(new OnItemClickListener() {

							@Override
							public void onItemClick(AdapterView<?> arg0,
													View arg1, final int arg2, long arg3) {
								// TODO Auto-generated method stub
								// String replyPreFix = "";
								// replyPreFix = "回复"
								// + adapter.listdata.get(arg2)
								// .getRealname() + ":";
								// isReplyPerson = true;
								// commentId = adapter.listdata.get(arg2)
								// .getMessid();
								// startComment(replyPreFix);

								reply.setOnClickListener(new OnClickListener() {

									@Override
									public void onClick(View arg0) {
										// TODO Auto-generated method stub
										mPw.dismiss();
										String replyPreFix = "";
										replyPreFix = "回复"
												+ adapter.listdata.get(arg2)
												.getRealname() + ":";
										commentId = adapter.listdata.get(arg2)
												.getMessid();
										isReplyPerson = true;
										startComment(replyPreFix);
									}
								});
								cancel.setOnClickListener(new OnClickListener() {

									@Override
									public void onClick(View arg0) {
										// TODO Auto-generated method stub
										mPw.dismiss();
									}
								});
								if (list.get(arg2).getIsme().equals("1")) {
									report.setText("删除");
									report.setOnClickListener(new OnClickListener() {

										@Override
										public void onClick(View arg0) {
											// TODO Auto-generated method stub
											reqDeltCmt(list.get(arg2)
													.getMessid());
											adapter.listdata.remove(arg2);
											adapter.notifyDataSetChanged();
											mPw.dismiss();

										}
									});
								} else {
									report.setOnClickListener(new OnClickListener() {

										@Override
										public void onClick(View arg0) {
											// TODO Auto-generated method stub
											mPw.dismiss();
											Intent intent = new Intent(
													mContext,
													ReportActivity.class);
											intent.putExtra("id", list
													.get(arg2).getMessid());
											startActivity(intent);
										}
									});
								}

								// Drawable dr =
								// this.getResources().getDrawable(R.drawable.list_bg_click);
								//
								// mPw.setBackgroundDrawable(dr);
								mPw.showAsDropDown(arg1);
							}
						});

					}

					@Override
					public void onError(VolleyError volleyError) {
						// TODO Auto-generated method stub
						mPullLayout.loadmoreFinish(mPullLayout.FAIL);
					}
				});
	}

	//删除评论
	void reqDeltCmt(final String id) {

		VolleyBasic.getInstance((Activity) mContext).post(Cache.delcomment,
				VolleyMap.getInstance().delcomment(id), OneStateIntParser.class,
				new VolleyCallback() {

					@Override
					public void onSuccess(VolleyData vd) {
						// TODO Auto-generated method stub
						if (vd.getCode() == -99) {
							AppUtil.Logout(getActivity());
							AppUtil.LoginVer(getActivity());
							return;
						}

					}

					@Override
					public void onError(VolleyError volleyError) {
						// TODO Auto-generated method stub

					}
				});
	}
	//点赞接口
	void reqLike(final String id, final Boolean setFollow) {
		String state = "";
		if (setFollow) {
			state = "1";
		} else {
			state = "2";
		}
		VolleyBasic.getInstance((Activity) mContext).post(
				Cache.artSupport,
				VolleyMap.getInstance().artSupport(id,
						AppUtil.getUser().getToken(), state), OneStateIntParser.class,
				new VolleyCallback() {

					@Override
					public void onSuccess(VolleyData vd) {
						// TODO Auto-generated method stub
						if (vd.getCode() == -99) {
							AppUtil.Logout(getActivity());
							AppUtil.LoginVer(getActivity());
							return;
						}
						if(setFollow){
							mImgLike.setImageResource(R.drawable.icon_like_sel);
						}else{
							mImgLike.setImageResource(R.drawable.like_orange);
						}
						// ArtSupport itemArtistFollow = (ArtSupport)
						// vd.getData();
						// String text = textlike.getText().toString();
						// String strnum = text.substring(text.indexOf("(") + 1,
						// text.indexOf(")"));
						//
						// if (itemArtistFollow.getState().equals("1")) {
						// if (setFollow) {
						// imgLike.setVisibility(View.VISIBLE);
						// imgUnlike.setVisibility(View.GONE);
						//
						// try {
						// int num = Integer.valueOf(strnum);
						// num++;
						// textlike.setText("点赞  ("
						// + String.valueOf(num) + ")");
						// } catch (Exception e) {
						// // TODO: handle exception
						// }
						//
						// } else {
						// imgLike.setVisibility(View.GONE);
						// imgUnlike.setVisibility(View.VISIBLE);
						// try {
						// int num = Integer.valueOf(strnum);
						// num--;
						// textlike.setText("点赞  ("
						// + String.valueOf(num) + ")");
						// } catch (Exception e) {
						// // TODO: handle exception
						// }
						// }
						// // reqData();
						// }
					}

					@Override
					public void onError(VolleyError volleyError) {
						// TODO Auto-generated method stub

					}
				});
	}
	//收藏接口
	void reqCollect(final String id, final Boolean setCollect) {
		String state = "";
		if (setCollect) {
			state = "1";
		} else {
			state = "2";
		}
		VolleyBasic.getInstance((Activity) mContext).post(
				Cache.artFavorite,
				VolleyMap.getInstance().artFavorite(
						AppUtil.getUser().getToken(), id, state),
				ArtFavorite.class, new VolleyCallback() {

					@Override
					public void onSuccess(VolleyData vd) {
						if (vd.getCode() == -99) {
							AppUtil.Logout(getActivity());
							AppUtil.LoginVer(getActivity());
							return;
						}
						// TODO Auto-generated method stub
						ArtFavorite itemArtistFollow = (ArtFavorite) vd
								.getData();
						String text = textsc.getText().toString();
						String strnum = text.substring(text.indexOf("(") + 1,
								text.indexOf(")"));
						if (itemArtistFollow.getState().equals("1")) {
							if (setCollect) {
								imgColl.setVisibility(View.VISIBLE);
								imgUncoll.setVisibility(View.GONE);
								try {
									int num = Integer.valueOf(strnum);
									num++;
									textsc.setText("收藏  ("
											+ String.valueOf(num) + ")");
								} catch (Exception e) {
									// TODO: handle exception
								}
							} else {
								imgColl.setVisibility(View.GONE);
								imgUncoll.setVisibility(View.VISIBLE);
								try {
									int num = Integer.valueOf(strnum);
									num--;
									textsc.setText("收藏  ("
											+ String.valueOf(num) + ")");
								} catch (Exception e) {
									// TODO: handle exception
								}
							}
						}

					}

					@Override
					public void onError(VolleyError volleyError) {
						// TODO Auto-generated method stub

					}
				});
	}
	//判断是会否点赞
	void reqisLike(String id) {
		VolleyBasic.getInstanceNoDialog(getActivity()).post(
				Cache.artShownum,
				VolleyMap.getInstance().artShownum(
						AppUtil.getUser().getToken(), id), ArtShownum.class,
				new VolleyCallback() {

					@Override
					public void onSuccess(VolleyData vd) {
						if (vd.getCode() == -99) {
							AppUtil.Logout(getActivity());
							AppUtil.LoginVer(getActivity());
							return;
						}
						// TODO Auto-generated method stub
						ArtShownum itemArtShownum = (ArtShownum) vd.getData();
						if (itemArtShownum.getCommend_state().equals("0")) {
							imgLike.setVisibility(View.GONE);
							imgUnlike.setVisibility(View.VISIBLE);
						} else {
							imgLike.setVisibility(View.VISIBLE);
							imgUnlike.setVisibility(View.GONE);
						}
						if (itemArtShownum.getFavorite_state().equals("0")) {
							imgColl.setVisibility(View.GONE);
							imgUncoll.setVisibility(View.VISIBLE);
						} else {
							imgColl.setVisibility(View.VISIBLE);
							imgUncoll.setVisibility(View.GONE);
						}
					}

					@Override
					public void onError(VolleyError volleyError) {
						// TODO Auto-generated method stub

					}
				});
	}

	void reqArtReplycomment() {
		VolleyBasic.getInstance(getActivity()).post(
				Cache.artReplycomment,
				VolleyMap.getInstance().artReplycomment(
						AppUtil.getUser().getToken(), id,
						editComment.getText().toString()), ArtistFollow.class,
				new VolleyCallback() {
					@Override
					public void onSuccess(VolleyData vd) {
						// TODO Auto-generated method stub
						if (vd.getCode() == -99) {
							Config.showTip(getActivity(), "请先登录");
							AppUtil.Logout(getActivity());
							AppUtil.LoginVer(getActivity());
							return;
						}
						ArtistFollow list = (ArtistFollow) vd.getData();

						if (list.getState().equals("1")) {
							reqCommentData();
							editComment.setText("");
							// setColLikeComment(true, textpl);
						}
					}

					@Override
					public void onError(VolleyError volleyError) {
						// TODO Auto-generated method stub

					}
				});

	}

	// 回复某人
	void Replycomment(String commentid) {
		if (TextUtils.isEmpty(editComment.getText().toString())) {
			Config.showTip(getActivity(), "回复不能为空");
			return;
		}
		String contentString = "";
		// if (editComment.getHint().toString()
		// .contains(AppUtil.getUser().getRealname())) {
		// reqArtReplycomment();
		// return;
		// } else {
		// contentString = editComment.getHint()
		// + editComment.getText().toString();
		// }

		VolleyBasic.getInstance(getActivity()).post(
				Cache.artAnswercomment,
				VolleyMap.getInstance().artAnswercomment(id,
						editComment.getText().toString(), commentid),
				ArtistFollow.class, new VolleyCallback() {
					@Override
					public void onSuccess(VolleyData vd) {
						if (vd.getCode() == -99) {
							Config.showTip(getActivity(), "请先登录");
							AppUtil.Logout(getActivity());
							AppUtil.LoginVer(getActivity());
							return;
						}
						ArtistFollow list = (ArtistFollow) vd.getData();

						if (list.getState().equals("1")) {
							reqCommentData();
							isReplyPerson = false;
							editComment.setText("");
							// setColLikeComment(true, textpl);
						}
					}

					@Override
					public void onError(VolleyError volleyError) {
						// TODO Auto-generated method stub
						Log.d("log", "回复出错:" + volleyError.toString());
					}
				});

	}

	// void setColLikeComment(Boolean isUp, TextView setView) {
	// String strTxt = setView.getText().toString();
	// String strnum = strTxt.substring(strTxt.indexOf("(") + 1,
	// strTxt.indexOf(")"));
	// try {
	// int num = Integer.valueOf(strnum);
	// if (isUp) {
	// num++;
	// } else {
	// num--;
	// }
	// if (strTxt.contains("收藏")) {
	// textsc.setText("收藏  (" + String.valueOf(num) + ")");
	// }
	// if (strTxt.contains("点赞")) {
	// textlike.setText("点赞  (" + String.valueOf(num) + ")");
	// }
	// if (strTxt.contains("评论")) {
	// textpl.setText("评论  (" + String.valueOf(num) + ")");
	// }
	// } catch (Exception e) {
	// // TODO: handle exception
	// }
	//
	// }

	void startComment(String strPreFix) {
		editComment.setHint(strPreFix);
		editComment.setFocusable(true);
		InputMethodManager imm = (InputMethodManager) editComment.getContext()
				.getSystemService(Context.INPUT_METHOD_SERVICE);
		imm.toggleSoftInput(0, InputMethodManager.SHOW_FORCED);
		mscroll.fullScroll(ScrollView.FOCUS_DOWN);
		hideView.setVisibility(View.VISIBLE);
		editComment.requestFocus();
	}

	void hideKeyBoard() {
		InputMethodManager imm = (InputMethodManager) getActivity()
				.getSystemService("input_method");
		if (imm != null) {
			imm.hideSoftInputFromWindow(getActivity().getWindow()
					.getDecorView().getWindowToken(), 0);
		}
		hideView.setVisibility(View.GONE);
	}

	@Override
	public void onClick(View arg0) {
		// TODO Auto-generated method stub

		switch (arg0.getId()) {
			case R.id.back_btn:
				getActivity().finish();
				break;
			case R.id.clt_det_pl:
				mscroll.fullScroll(ScrollView.FOCUS_DOWN);
				break;
			case R.id.clt_det_icon_view:
				Intent intent2 = new Intent(mContext, DotPraiseUser_Activity.class);
				intent2.putExtra("id", id);
				startActivity(intent2);
				break;
			case R.id.clt_det_chat:

				String headUrl;
				if (!TextUtils.isEmpty(MainData.getHeadurl())) {
					headUrl = MainData.getHeadurl();
				} else {
					headUrl = "http://172.16.0.3/upload/artPlatform/Addons/Avatar/default_128_128.png";
				}
				AppUtil.goChat(mContext, MainData.getUid(), headUrl,
						MainData.getRealname());

				break;

			case R.id.iv_coll_img:
				Intent intent = new Intent(getActivity(), PhotoActivity.class);
				intent.putExtra("item", photoItem);
				startActivity(intent);
				break;
			case R.id.view_like:
				// if (AppUtil.LoginVer(getActivity())) {
				// return;
				// }
				// if (imgLike.getVisibility() == View.VISIBLE) {
				// + AppUtil.picWidthUrl)
				// // .load("/storage/emulated/0/Tencent/QQfile_recv/55mb.jpg")
				// .asBitmap()
				// .into(new SimpleTarget<Bitmap>() {
				// @Override
				// public void onResourceReady(
				// Bitmap resource,
				// GlideAnimation<? super Bitmap> glideAnimation) {
				// CircleImageView img = new CircleImageView(
				// mContext);
				// img.setImageBitmap(resource);
				// android.widget.LinearLayout.LayoutParams params = new
				// android.widget.LinearLayout.LayoutParams(
				// com.aicpsp.artworkartc.util.VeDate
				// .dip2px(mContext,
				// 30),
				// com.aicpsp.artworkartc.util.VeDate
				// .dip2px(mContext,
				// 30));
				// img.setLayoutParams(params);
				// params.setMargins(com.aicpsp.artworkartc.util.VeDate
				// .dip2px(mContext,
				// 10), 0, com.aicpsp.artworkartc.util.VeDate
				// .dip2px(mContext,
				// 10), 0);
				// mLineIcon.addView(img);
				// }
				// });
				// } else {
				// reqLike(id, true);
				// }

				break;

			case R.id.view_collect:
				if (AppUtil.LoginVer(getActivity())) {
					return;
				}
				if (imgColl.getVisibility() == View.VISIBLE) {
					reqCollect(id, false);
				} else {
					reqCollect(id, true);
				}

				break;

			case R.id.artdet_comment_show:
				startComment("");
				isReplyPerson = false;
				break;

			case R.id.collection_det_hideview:
				hideKeyBoard();

				break;
			case R.id.artdet_comment_edit:
				hideView.setVisibility(View.VISIBLE);
				break;
			case R.id.clt_det_more:

				if (AppUtil.isCollect) {
					AppUtil.shareClt(mContext, MainData.getTitle(),
							MainData.getDetail(), MainData.getPic_url(),
							MainData.getSharelink(), id, true);
				} else {
					AppUtil.shareClt(mContext, MainData.getTitle(),
							MainData.getDetail(), MainData.getPic_url(),
							MainData.getSharelink(), id, false);
				}

				break;
			case R.id.clt_det_back:
				getActivity().finish();
				break;
			case R.id.clt_det_like:
				String head = AppUtil.getUser().getHeadurl();
				if(listIcon!=null){
					if (islike) {
						reqLike(id, false);
						islike = false;
						if(listIcon.size()!=0){
							listIcon.remove(listIcon.indexOf(head));
						}
					} else {
						reqLike(id, true);
						islike = true;
						// mLineIcon.addView(headIconForLike);
						listIcon.add(head);
					}
				}
				setHeadIcon(listIcon);
				break;
			case R.id.clt_det_artistInfoRL:
				if(MainData!=null) {
					if ("1".equals(MainData.getIs_artist())) {
						//艺术家
						Intent intent3 = new Intent(mContext, CollecterActivity.class);
						intent3.putExtra("id", artistID);
						mContext.startActivity(intent3);
					} else {
						//机构
						Intent intent4 = new Intent(mContext, OrganizationActivity.class);
						intent4.putExtra("id", artistID);
						startActivity(intent4);
					}
				}
				break;
			default:
				break;
		}
	}

	/**
	 * 分享传递到上层activity
	 *
	 * @return
	 */
	public ShareItem getShareitem() {
		return shareItem;
	}

}
